package foo.bar;

import foo.bar.db.Dao.EmployeeDao;
import foo.bar.db.Dao.PersonDao;
import foo.bar.db.Dao.impl.MongoEmployeeDao;
import foo.bar.db.Dao.impl.MongoPersonDao;
import foo.bar.db.entity.Employee;
import foo.bar.db.entity.Person;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

public class HelloApp {
    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml");
        EmployeeDao employeeDao = context.getBean("mongoEmployeeDao", MongoEmployeeDao.class);
        PersonDao personDao = context.getBean("mongoPersonDao", MongoPersonDao.class);
//        Employee employee = new Employee("Vasya", 25);
//        System.out.println(employee);
//        System.out.println();
//
//        employeeDao.save(employee);
//
//        System.out.println(employee);
//
//        System.out.println("Reading from db");
//        List<Employee> employeeList = employeeDao.findAll();
//        for(Employee employee1 : employeeList){
//            System.out.println(employee1);
//        }
        Person person = new Person("Vasiliy", "Pupochkin");
        Employee employee = new Employee("vasP", person, 42);
        System.out.println(employee);
        personDao.save(person);
        employeeDao.save(employee);
        System.out.println(employee);
        Employee employee1 = employeeDao.findById(employee.getId());
        System.out.println(employee1);

    }
}
